//package org.darkforest.controller;
//
//import com.wordnik.swagger.annotations.Api;
//import com.wordnik.swagger.annotations.ApiOperation;
//import org.darkforest.auth.CurrentMember;
//import org.darkforest.common.util.DateUtil;
//import org.darkforest.dao.mapper.FestivalMapper;
//import org.darkforest.dao.mapper.FestivalRemindMapper;
//import org.darkforest.dao.mapper.MemberFriendsMapper;
//import org.darkforest.dao.mapper.RelationMapper;
//import org.darkforest.model.*;
//import org.darkforest.auth.AuthPassport;
//import org.darkforest.ucenter.service.ContactsService;
//import org.darkforest.ucenter.service.FestivalRemindService;
//import org.darkforest.vo.MemberBase;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.MediaType;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.*;
//import org.springframework.web.servlet.ModelAndView;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpSession;
//import java.util.Date;
//import java.util.List;
//
///**
// * Created by pc on 2017/4/20.
// */
//@RestController
//@RequestMapping(value = "contacts")
//@Api(value = "contacts", description = "人脉圈", produces = MediaType.APPLICATION_JSON_VALUE)
//public class ContactsController {
//
//    @Autowired
//    private FestivalRemindService festivalRemindService;
//    @Autowired
//    private FestivalMapper festivalMapper;
//    @Autowired
//    private MemberFriendsMapper memberFriendsMapper;
//    @Autowired
//    private RelationMapper relationMapper;
//    @Autowired
//    private FestivalRemindMapper festivalRemindMapper;
//    @Autowired
//    private ContactsService contactsService;
//
//    /****
//     * 人脉圈列表(生日、纪念日)
//     *
//     * @return
//     */
//    @AuthPassport
//    @RequestMapping(value = "list", method = RequestMethod.GET)
//    @ApiOperation(value = "人脉圈提醒列表 fRemindType(1:生日、2：纪念日、空则全部) ", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
//    public RestEntity list(@CurrentMember Member member,
//                           @RequestParam(required = false, defaultValue = "") String fRemindType,
//                           @RequestParam(required = false, defaultValue = "") String fName,
//                           @RequestParam(required = false, defaultValue = "0") Integer start,
//                           @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
//        try {
//            Integer userId = member.getMemberId();
//            FestivalRemind record = new FestivalRemind();
//            record.setCreaterId(userId);
//            record.setfName(fName);
//            record.setStart(start);
//            record.setPageSize(pageSize);
//            record.setfRemindType(fRemindType);
//            record = festivalRemindService.selectListByCondition(record);
//            return RestEntity.success(record.getResultList());
//        } catch (Exception e) {
//            e.printStackTrace();
//            return RestEntity.failed();
//        }
//
//    }
//
//    @AuthPassport
//    @RequestMapping(value = "addanniversary", method = RequestMethod.POST)
//    @ApiOperation(value = "纪念日添加", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
//    public RestEntity addanniversary(@CurrentMember Member member, @RequestBody FestivalRemind record) {
//        try {
//            contactsService.addanniversary(record, new MemberBase(member.getMemberId(), member.getMemberName()));
//            return RestEntity.success("添加成功");
//        } catch (Exception e) {
//            e.printStackTrace();
//            return RestEntity.failed();
//        }
//    }
//
//    @AuthPassport
//    @RequestMapping(value = "delanniversary", method = RequestMethod.GET)
//    @ApiOperation(value = "根据ID纪念日删除", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
//    public RestEntity delanniversary( @RequestParam(required = true) Integer fId) {
//        try {
//            festivalRemindMapper.deleteByPrimaryKey(fId);
//            return RestEntity.success("删除成功");
//        } catch (Exception e) {
//            e.printStackTrace();
//            return RestEntity.failed();
//        }
//    }
//
//    /****
//     * 节日列表
//     *
//     * @return
//     */
//    @AuthPassport
//    @RequestMapping(value = "festivallist", method = RequestMethod.GET)
//    @ApiOperation(value = "节日列表", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
//    public RestEntity festivallist(@RequestParam(required = false, defaultValue = "0") Integer start,
//                                   @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
//        try {
//            Festival festival = new Festival();
//            festival.setStart(start);
//            festival.setPageSize(pageSize);
//            festival.setCurrateDate(DateUtil.dateToString(new Date(), DateUtil.DEFAULT_DATE_PATTERN));
//            return RestEntity.success(festivalMapper.selectListByCondition(festival));
//        } catch (Exception e) {
//            e.printStackTrace();
//            return RestEntity.failed();
//        }
//    }
//
//    /******
//     * 联系人列表
//     *
//     * @return
//     */
//    @AuthPassport
//    @RequestMapping(value = "friendslist", method = RequestMethod.GET)
//    @ApiOperation(value = "联系人列表", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
//    public RestEntity friendslist(@CurrentMember Member member,
//                                  @RequestParam(required = false, defaultValue = "0") Integer start,
//                                  @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
//        try {
//            MemberFriends record = new MemberFriends();
//            record.setCreaterId(member.getMemberId());
//            record.setPageSize(pageSize);
//            record.setStart(start);
//            return RestEntity.success(memberFriendsMapper.selectByCondition(record));
//        } catch (Exception e) {
//            e.printStackTrace();
//            return RestEntity.failed();
//        }
//    }
//
//
//    @AuthPassport
//    @RequestMapping(value = "relationList", method = RequestMethod.GET)
//    @ApiOperation(value = "关系列表", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
//    public RestEntity relationList() {
//        try {
//            Relation relation = new Relation();
//            relation.setPageSwitch(false);
//            relation.setrState(1);
//            List<Relation> list = relationMapper.selectListByCondition(relation);
//            return RestEntity.success(list);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return RestEntity.failed();
//        }
//    }
//
//    @AuthPassport
//    @RequestMapping(value = "addfriends", method = RequestMethod.POST)
//    @ApiOperation(value = "联系人添加", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
//    public RestEntity addfriends(@CurrentMember Member member, @RequestBody MemberFriends record) {
//        try {
//            contactsService.addfriends(record, new MemberBase(member.getMemberId(), member.getMemberName()));
//            return RestEntity.success("添加成功");
//        } catch (Exception e) {
//            e.printStackTrace();
//            return RestEntity.failed();
//        }
//    }
//
//    @AuthPassport
//    @RequestMapping(value = "toeditfriends", method = RequestMethod.GET)
//    @ApiOperation(value = "根据ID获取联系人", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
//    public RestEntity toeditfriends( @RequestParam(required = true) Integer fId) {
//        try {
//            MemberFriends record = memberFriendsMapper.selectByPrimaryKey(fId);
//            FestivalRemind festivalRemind = new FestivalRemind();
//            festivalRemind.setfRelationMemberIds(String.valueOf(fId));
//            festivalRemind.setfRemindType("1");
//            List<FestivalRemind> list = festivalRemindMapper.selectListByCondition(festivalRemind);
//            if (list.size() > 0 && list.get(0) != null) {
//                record.setBirthday(list.get(0).getfDate());
//            }
//            return RestEntity.success(record);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return RestEntity.failed();
//        }
//    }
//
//    @AuthPassport
//    @RequestMapping(value = "editfriends", method = RequestMethod.POST)
//    @ApiOperation(value = "联系人编辑", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
//    public RestEntity doeditfriends(@CurrentMember Member member, @RequestBody MemberFriends record) {
//        try {
//            contactsService.editfriends(record, new MemberBase(member.getMemberId(), member.getMemberName()));
//            return RestEntity.success("编辑成功");
//        } catch (Exception e) {
//            e.printStackTrace();
//            return RestEntity.failed();
//        }
//    }
//
//    @AuthPassport
//    @RequestMapping(value = "delfriends", method = RequestMethod.GET)
//    @ApiOperation(value = "联系人删除", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
//    public RestEntity todelfriends( @RequestParam(required = true) Integer fId) {
//        try {
//            contactsService.delfriends(fId);
//            return RestEntity.success("删除成功");
//        } catch (Exception e) {
//            e.printStackTrace();
//            return RestEntity.failed();
//        }
//    }
//
//
//    @AuthPassport
//    @RequestMapping(value = "onefriends", method = RequestMethod.GET)
//    @ApiOperation(value = "根据ID获取联系人相关提醒", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
//    public RestEntity onefriends( @RequestParam(required = true) Integer fId) {
//        try {
//            FestivalRemind festivalRemind = new FestivalRemind();
//            festivalRemind.setfRelationMemberIds(String.valueOf(fId));
//            festivalRemind.setPageSwitch(false);
//            List<FestivalRemind> list = festivalRemindMapper.selectFriendsFestivals(festivalRemind);
//            return RestEntity.success(list);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return RestEntity.failed();
//        }
//    }
//
//    @AuthPassport
//    @RequestMapping(value = "festivals", method = RequestMethod.GET)
//    @ApiOperation(value = "获取所有节日", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
//    public RestEntity toaddgiftfestival() {
//        try {
//            Festival festival = new Festival();
//            festival.setPageSwitch(false);
//            List<Festival> festivals = festivalMapper.selectListByCondition(festival);
//            return RestEntity.success(festivals);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return RestEntity.failed();
//        }
//    }
//
//    @AuthPassport
//    @RequestMapping(value = "doaddgiftfestival", method = RequestMethod.POST)
//    @ApiOperation(value = "添加联系人提醒", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
//    public RestEntity doaddgiftfestival(@CurrentMember Member member,  @RequestParam(required = true) Integer memberFriendsId,  @RequestParam(required = true) String form_type,  @RequestParam(required = true) String ids, @RequestBody Festival record) {
//        try {
//            contactsService.addgiftfestival(memberFriendsId, form_type, ids, record, new MemberBase(member.getMemberId(), member.getMemberName()));
//            return RestEntity.success("添加成功");
//        } catch (Exception e) {
//            e.printStackTrace();
//            return RestEntity.failed();
//        }
//    }
//}
